# encoding: utf-8
# @File  : page_index.py
# @Author: wu shaofan
# @Date  :  2024/04/18
# @Desc :
from selenium.webdriver.common.by import By
from PO.base.base import Base


class PageIndex(Base):
    # 商品搜索框
    search_info = By.ID, 'q'
    # 搜索按钮
    search_btn = By.CLASS_NAME, 'ecsc-search-button'
    # 点击登录按钮
    index_login_btn = By.CLASS_NAME, 'red'
    # 添加商品数量
    add_goods_num = By.CSS_SELECTOR, 'div[class="p-num"] input'
    # 点击加入购物车按钮
    add_cart_btn = By.LINK_TEXT, '加入购物车'
    # 进入if框架
    iframe01 = By.CSS_SELECTOR, 'div[class="layui-layer-content"] iframe'
    # 获取加入购物车后的提示信息
    add_cart_success_info = By.CSS_SELECTOR, 'div[class="conect-title"] span'
    # 点击关闭弹框按钮
    close_btn = By.CSS_SELECTOR, '.layui-layer-ico.layui-layer-close.layui-layer-close1'
    # 点击购物车按钮
    cart_btn = By.CSS_SELECTOR, 'div[class="c-n fl"] span'
    
    # 搜索框内输入信息
    def page_input_search_info(self, info):
        self.base_input_no_clear(self.search_info, info)

    # 点击搜索按钮
    def page_click_search_btn(self):
        self.base_click(self.search_btn)

    # 刷新页面
    def page_refresh_index(self):
        self.base_refresh()

    # 点击登录按钮
    def page_click_index_login_btn(self):
        self.base_click(self.index_login_btn)

    # 添加商品数量
    def page_add_goods_num(self, num):
        self.base_input(self.add_goods_num, num)

    # 点击加入购物车按钮
    def page_click_add_cart_btn(self):
        self.base_click(self.add_cart_btn)

    # 进入iframe框架
    def page_into_iframe01(self):
        self.base_if_frame_exist(self.iframe01)
        self.base_get_allure_image()

    # 获取弹框中加入购物车成功提示信息
    def page_get_add_cart_success_info(self):
        return self.base_get_text(self.add_cart_success_info)

    # 点击关闭弹框按钮
    def page_click_close_btn(self):
        self.base_click(self.close_btn)
        self.base_get_allure_image()

    # 点击购物车按钮
    def page_click_cart_btn(self):
        self.base_click(self.cart_btn)
        self.base_get_allure_image()
